package com.asianrapid.controller.sys;


import com.asianrapid.model.sys.FurnitrunEntity;
import com.asianrapid.model.sys.PageResult;
import com.asianrapid.service.sys.FurnitrunService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
public class FurnitrunController {
    private Logger log = LoggerFactory.getLogger(FurnitrunController.class);

    @Autowired
    private FurnitrunService furnitrunService;

    @GetMapping("/furnitrun")
    public PageResult getFurnitrunCar(int pageSize, int page){

        PageResult pageResult = new PageResult();
        pageResult.setData(furnitrunService.furnitrunList( pageSize,page * pageSize ));
        pageResult.setTotalCount(furnitrunService.furnitrunSize( pageSize,page * pageSize ));
        log.debug("The method is ending");

        return pageResult;

    }


    @PostMapping("/menus/furnitrun")
    public void insertFurnitrun(@RequestBody FurnitrunEntity furnitrunEntity){
        furnitrunService.insertFurnitrun(furnitrunEntity);
    }

    @GetMapping("/XL/furnitrun")
    public PageResult getXL(){
        PageResult pageResult = new PageResult();
        pageResult.setData(furnitrunService.tableList());
        return pageResult;
    }/*furnitrun*/


    @PutMapping("/furnitrun/{id}")
    public FurnitrunEntity updateFurnitrun(@RequestBody FurnitrunEntity furnitrunEntity, @PathVariable int id) {
        if (furnitrunEntity.getId() == id) {
            furnitrunService.updateFurnitrun(furnitrunEntity);
        }
        log.debug("The method is ending");
        return furnitrunEntity;
    }
//    delFurnitrun


    @DeleteMapping("/delFurnitrun")
    public List<String> deleteFurnitrun(@RequestBody List<String> groupId) {
        furnitrunService.deleteFurnitrun(groupId);
        return groupId;
    }/*/zgr/furnitrun*/


    @PostMapping("/zgr/furnitrun")
    public FurnitrunEntity getFurnitrun(@RequestBody List<Integer> groupId){

        return furnitrunService.getFurnitrun(groupId.get(0));

    }
}
